package org.jivesoftware.smack.packet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class XMPPError
{
  private List<PacketExtension> applicationExtensions = null;
  private int code;
  private String condition;
  private String message;
  private Type type;

  public XMPPError(int paramInt)
  {
    this.code = paramInt;
    this.message = null;
  }

  public XMPPError(int paramInt, String paramString)
  {
    this.code = paramInt;
    this.message = paramString;
  }

  public XMPPError(int paramInt, Type paramType, String paramString1, String paramString2, List<PacketExtension> paramList)
  {
    this.code = paramInt;
    this.type = paramType;
    this.condition = paramString1;
    this.message = paramString2;
    this.applicationExtensions = paramList;
  }

  public XMPPError(Condition paramCondition)
  {
    init(paramCondition);
    this.message = null;
  }

  public XMPPError(Condition paramCondition, String paramString)
  {
    init(paramCondition);
    this.message = paramString;
  }

  private void init(Condition paramCondition)
  {
    ErrorSpecification localErrorSpecification = ErrorSpecification.specFor(paramCondition);
    this.condition = Condition.access$0(paramCondition);
    if (localErrorSpecification != null)
    {
      this.type = localErrorSpecification.getType();
      this.code = localErrorSpecification.getCode();
    }
  }

  /**
   * @deprecated
   */
  public void addExtension(PacketExtension paramPacketExtension)
  {
    monitorenter;
    try
    {
      if (this.applicationExtensions == null)
        this.applicationExtensions = new ArrayList();
      this.applicationExtensions.add(paramPacketExtension);
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public int getCode()
  {
    return this.code;
  }

  public String getCondition()
  {
    return this.condition;
  }

  /**
   * @deprecated
   */
  public PacketExtension getExtension(String paramString1, String paramString2)
  {
    Object localObject2;
    PacketExtension localPacketExtension;
    monitorenter;
    try
    {
      boolean bool;
      List localList = this.applicationExtensions;
      if ((localList == null) || (paramString1 == null) || (paramString2 == null))
      {
        localObject2 = null;
        monitorexit;
        return localObject2;
      }
      Iterator localIterator = this.applicationExtensions.iterator();
      do
      {
        do
        {
          while (!(localIterator.hasNext()))
            localObject2 = null;
          localPacketExtension = (PacketExtension)localIterator.next();
        }
        while (!(paramString1.equals(localPacketExtension.getElementName())));
        bool = paramString2.equals(localPacketExtension.getNamespace());
      }
      while (!(bool));
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public List<PacketExtension> getExtensions()
  {
    List localList1;
    Object localObject2;
    monitorenter;
    try
    {
      if (this.applicationExtensions == null)
      {
        List localList2 = Collections.emptyList();
        localObject2 = localList2;
        monitorexit;
        return localObject2;
      }
      localList1 = Collections.unmodifiableList(this.applicationExtensions);
    }
    finally
    {
      monitorexit;
    }
  }

  public String getMessage()
  {
    return this.message;
  }

  public Type getType()
  {
    return this.type;
  }

  /**
   * @deprecated
   */
  public void setExtension(List<PacketExtension> paramList)
  {
    monitorenter;
    try
    {
      this.applicationExtensions = paramList;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public String toString()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    if (this.condition != null)
      localStringBuilder.append(this.condition);
    localStringBuilder.append("(").append(this.code).append(")");
    if (this.message != null)
      localStringBuilder.append(" ").append(this.message);
    return localStringBuilder.toString();
  }

  public String toXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<error code=\"").append(this.code).append("\"");
    if (this.type != null)
    {
      localStringBuilder.append(" type=\"");
      localStringBuilder.append(this.type.name());
      localStringBuilder.append("\"");
    }
    localStringBuilder.append(">");
    if (this.condition != null)
    {
      localStringBuilder.append("<").append(this.condition);
      localStringBuilder.append(" xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>");
    }
    if (this.message != null)
    {
      localStringBuilder.append("<text xml:lang=\"en\" xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">");
      localStringBuilder.append(this.message);
      localStringBuilder.append("</text>");
    }
    Iterator localIterator = getExtensions().iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
      {
        localStringBuilder.append("</error>");
        return localStringBuilder.toString();
      }
      localStringBuilder.append(((PacketExtension)localIterator.next()).toXML());
    }
  }

  public static class Condition
  {
    public static final Condition bad_request;
    public static final Condition conflict;
    public static final Condition feature_not_implemented;
    public static final Condition forbidden;
    public static final Condition gone;
    public static final Condition interna_server_error = new Condition("internal-server-error");
    public static final Condition item_not_found;
    public static final Condition jid_malformed;
    public static final Condition no_acceptable;
    public static final Condition not_allowed;
    public static final Condition not_authorized;
    public static final Condition payment_required;
    public static final Condition recipient_unavailable;
    public static final Condition redirect;
    public static final Condition registration_required;
    public static final Condition remote_server_error;
    public static final Condition remote_server_not_found;
    public static final Condition remote_server_timeout;
    public static final Condition request_timeout;
    public static final Condition resource_constraint;
    public static final Condition service_unavailable;
    public static final Condition subscription_required;
    public static final Condition undefined_condition;
    public static final Condition unexpected_request;
    private String value;

    static
    {
      forbidden = new Condition("forbidden");
      bad_request = new Condition("bad-request");
      conflict = new Condition("conflict");
      feature_not_implemented = new Condition("feature-not-implemented");
      gone = new Condition("gone");
      item_not_found = new Condition("item-not-found");
      jid_malformed = new Condition("jid-malformed");
      no_acceptable = new Condition("not-acceptable");
      not_allowed = new Condition("not-allowed");
      not_authorized = new Condition("not-authorized");
      payment_required = new Condition("payment-required");
      recipient_unavailable = new Condition("recipient-unavailable");
      redirect = new Condition("redirect");
      registration_required = new Condition("registration-required");
      remote_server_error = new Condition("remote-server-error");
      remote_server_not_found = new Condition("remote-server-not-found");
      remote_server_timeout = new Condition("remote-server-timeout");
      resource_constraint = new Condition("resource-constraint");
      service_unavailable = new Condition("service-unavailable");
      subscription_required = new Condition("subscription-required");
      undefined_condition = new Condition("undefined-condition");
      unexpected_request = new Condition("unexpected-request");
      request_timeout = new Condition("request-timeout");
    }

    public Condition(String paramString)
    {
      this.value = paramString;
    }

    public String toString()
    {
      return this.value;
    }
  }

  private static class ErrorSpecification
  {
    private static Map<XMPPError.Condition, ErrorSpecification> instances = errorSpecifications();
    private int code;
    private XMPPError.Condition condition;
    private XMPPError.Type type;

    private ErrorSpecification(XMPPError.Condition paramCondition, XMPPError.Type paramType, int paramInt)
    {
      this.code = paramInt;
      this.type = paramType;
      this.condition = paramCondition;
    }

    private static Map<XMPPError.Condition, ErrorSpecification> errorSpecifications()
    {
      HashMap localHashMap = new HashMap(22);
      localHashMap.put(XMPPError.Condition.interna_server_error, new ErrorSpecification(XMPPError.Condition.interna_server_error, XMPPError.Type.WAIT, 500));
      localHashMap.put(XMPPError.Condition.forbidden, new ErrorSpecification(XMPPError.Condition.forbidden, XMPPError.Type.AUTH, 403));
      localHashMap.put(XMPPError.Condition.bad_request, new ErrorSpecification(XMPPError.Condition.bad_request, XMPPError.Type.MODIFY, 400));
      localHashMap.put(XMPPError.Condition.item_not_found, new ErrorSpecification(XMPPError.Condition.item_not_found, XMPPError.Type.CANCEL, 404));
      localHashMap.put(XMPPError.Condition.conflict, new ErrorSpecification(XMPPError.Condition.conflict, XMPPError.Type.CANCEL, 409));
      localHashMap.put(XMPPError.Condition.feature_not_implemented, new ErrorSpecification(XMPPError.Condition.feature_not_implemented, XMPPError.Type.CANCEL, 501));
      localHashMap.put(XMPPError.Condition.gone, new ErrorSpecification(XMPPError.Condition.gone, XMPPError.Type.MODIFY, 302));
      localHashMap.put(XMPPError.Condition.jid_malformed, new ErrorSpecification(XMPPError.Condition.jid_malformed, XMPPError.Type.MODIFY, 400));
      localHashMap.put(XMPPError.Condition.no_acceptable, new ErrorSpecification(XMPPError.Condition.no_acceptable, XMPPError.Type.MODIFY, 406));
      localHashMap.put(XMPPError.Condition.not_allowed, new ErrorSpecification(XMPPError.Condition.not_allowed, XMPPError.Type.CANCEL, 405));
      localHashMap.put(XMPPError.Condition.not_authorized, new ErrorSpecification(XMPPError.Condition.not_authorized, XMPPError.Type.AUTH, 401));
      localHashMap.put(XMPPError.Condition.payment_required, new ErrorSpecification(XMPPError.Condition.payment_required, XMPPError.Type.AUTH, 402));
      localHashMap.put(XMPPError.Condition.recipient_unavailable, new ErrorSpecification(XMPPError.Condition.recipient_unavailable, XMPPError.Type.WAIT, 404));
      localHashMap.put(XMPPError.Condition.redirect, new ErrorSpecification(XMPPError.Condition.redirect, XMPPError.Type.MODIFY, 302));
      localHashMap.put(XMPPError.Condition.registration_required, new ErrorSpecification(XMPPError.Condition.registration_required, XMPPError.Type.AUTH, 407));
      localHashMap.put(XMPPError.Condition.remote_server_not_found, new ErrorSpecification(XMPPError.Condition.remote_server_not_found, XMPPError.Type.CANCEL, 404));
      localHashMap.put(XMPPError.Condition.remote_server_timeout, new ErrorSpecification(XMPPError.Condition.remote_server_timeout, XMPPError.Type.WAIT, 504));
      localHashMap.put(XMPPError.Condition.remote_server_error, new ErrorSpecification(XMPPError.Condition.remote_server_error, XMPPError.Type.CANCEL, 502));
      localHashMap.put(XMPPError.Condition.resource_constraint, new ErrorSpecification(XMPPError.Condition.resource_constraint, XMPPError.Type.WAIT, 500));
      localHashMap.put(XMPPError.Condition.service_unavailable, new ErrorSpecification(XMPPError.Condition.service_unavailable, XMPPError.Type.CANCEL, 503));
      localHashMap.put(XMPPError.Condition.subscription_required, new ErrorSpecification(XMPPError.Condition.subscription_required, XMPPError.Type.AUTH, 407));
      localHashMap.put(XMPPError.Condition.undefined_condition, new ErrorSpecification(XMPPError.Condition.undefined_condition, XMPPError.Type.WAIT, 500));
      localHashMap.put(XMPPError.Condition.unexpected_request, new ErrorSpecification(XMPPError.Condition.unexpected_request, XMPPError.Type.WAIT, 400));
      localHashMap.put(XMPPError.Condition.request_timeout, new ErrorSpecification(XMPPError.Condition.request_timeout, XMPPError.Type.CANCEL, 408));
      return localHashMap;
    }

    protected static ErrorSpecification specFor(XMPPError.Condition paramCondition)
    {
      return ((ErrorSpecification)instances.get(paramCondition));
    }

    protected int getCode()
    {
      return this.code;
    }

    protected XMPPError.Condition getCondition()
    {
      return this.condition;
    }

    protected XMPPError.Type getType()
    {
      return this.type;
    }
  }

  public static enum Type
  {
    static
    {
      CANCEL = new Type("CANCEL", 1);
      MODIFY = new Type("MODIFY", 2);
      AUTH = new Type("AUTH", 3);
      CONTINUE = new Type("CONTINUE", 4);
      Type[] arrayOfType = new Type[5];
      arrayOfType[0] = WAIT;
      arrayOfType[1] = CANCEL;
      arrayOfType[2] = MODIFY;
      arrayOfType[3] = AUTH;
      arrayOfType[4] = CONTINUE;
      ENUM$VALUES = arrayOfType;
    }
  }
}